package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.ExchangeGoldDiamondsLog;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class ExchangeGoldDiamondsLogDao extends BaseDao<ExchangeGoldDiamondsLog> {

    /**
     * 查询列表
     */
    public List<ExchangeGoldDiamondsLog> page(Map<String, Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select d.*,u.loginname,u.nick,u.pic from exchange_gold_diamonds_log d left join app_user u on u.id=d.userId where 1=1  ");
        if (StringEx.isNotNull(paraMap.get("startDate"))) {
            sbStr.append(" and DATE_FORMAT(d.createtime, '%Y-%m-%d')  >=  ? ");
            paramList.add(paraMap.get("startDate"));
        }
        if (StringEx.isNotNull(paraMap.get("endDate"))) {
            sbStr.append(" and DATE_FORMAT(d.createtime, '%Y-%m-%d')  <=  ? ");
            paramList.add(paraMap.get("endDate"));
        }
        if (StringEx.isNotNull(paraMap.get("userId"))) {
            sbStr.append(" and d.userId = ? ");
            paramList.add(paraMap.get("userId"));
        }
        sbStr.append(" order by d.createTime desc");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, ExchangeGoldDiamondsLog.class, splitPage);
    }

    public List<ExchangeGoldDiamondsLog> findList(Integer userId, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from exchange_gold_diamonds_log where userId = ? ");
        paramList.add(userId);
        sbStr.append(" order by createTime desc");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, ExchangeGoldDiamondsLog.class, splitPage);
    }

    /**
     * 详情
     */
    public ExchangeGoldDiamondsLog get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from exchange_gold_diamonds_log where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, ExchangeGoldDiamondsLog.class);
    }

    /**
     * 添加/修改
     */
    public void saveOrUpdate(ExchangeGoldDiamondsLog haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id <= 0) {
            return;
        }
        String sql = "delete  from exchange_gold_diamonds_log where id = ?";
        ArrayList<Object> paramList = new ArrayList<>();
        paramList.add(id);
        this.del(sql, paramList);
    }

}
